#
# @lc app=leetcode.cn id=309 lang=python
#
# [309] 买卖股票的最佳时机含冷冻期
#

# @lc code=start
class Solution(object):
    def maxProfit(self, prices):
        """
        :type prices: List[int]
        :rtype: int
        """
        dp = [[0]*3 for _ in range(len(prices))]
        dp[0][0] = -prices[0]

        for i in range(1, len(prices)):
            dp[i][0] = max(dp[i-1][0], dp[i-1][2]-prices[i])
            dp[i][1] = max(prices[i]+dp[i-1][0], dp[i-1][1])
            dp[i][2] = dp[i-1][1]
        return max(dp[-1][1], dp[-1][2])

        
# @lc code=end

